package com.wuzuqing.android.eightdiagrams

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.RadioGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.wuzuqing.android.eightdiagrams.base.BaseAdapter
import com.wuzuqing.android.eightdiagrams.dao.BaZhiHistory
import com.wuzuqing.android.eightdiagrams.db.DbManager
import com.wuzuqing.android.eightdiagrams.utils.*
import java.util.*

class BaZiQueueTimeActivity : BaseActivity() {
    lateinit var vRcvHistory: RecyclerView
    lateinit var vEtBazhi: EditText
    lateinit var mRgSex: RadioGroup
    private var mBaZhiHistoryAdapter = BaZhiHistoryAdapter()

    @SuppressLint("SimpleDateFormat")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_bazi_queue_time)
        vRcvHistory = findViewById(R.id.rcv)
        vEtBazhi = findViewById(R.id.et_bazi)
        mRgSex = findViewById(R.id.sex_container)
        findViewById<View>(R.id.btn_queue).setOnClickListener {
            val bzArr = vEtBazhi.text.toString().split(",")
            val isBoy = if (mRgSex.checkedRadioButtonId == R.id.sex_boy) 1 else 0
            val list: MutableList<BaZhiHistory> = DataUtils.getTimeByBaZi(bzArr, isBoy)
            mBaZhiHistoryAdapter.setList(list)
        }
        initResultRcv()
    }


    private fun initResultRcv() {
        vRcvHistory.layoutManager = LinearLayoutManager(this)
        vRcvHistory.adapter = mBaZhiHistoryAdapter
        mBaZhiHistoryAdapter.setOnItemClickListener(object : BaseAdapter.OnItemClickListener<BaZhiHistory> {
            override fun onItemClick(data: BaZhiHistory, position: Int) {
                startActivity(Intent(this@BaZiQueueTimeActivity, BaZiActivity::class.java).apply {
                    putExtra("data", data)
                })
                finish()
            }
        })
    }

}
